import { useEffect, useState } from 'react'

const useDebounce: <T>(value: T, delay: number) => T = (value, delay) => {
  const [debounceValue, setDebounceValue] = useState(value)
  useEffect(() => {
    const timer = setTimeout(() => {
      setDebounceValue(value)
    }, delay)
    return () => clearTimeout(timer)
  }, [value])
  return debounceValue
}

export default useDebounce
